package com.simple.sso.server.utils;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 存储token和对应系统的
 */
public enum ClientStorage {

    INSTANCE;

    private ConcurrentHashMap<String, Set<String>> tokenAndClientUrlsMap = new ConcurrentHashMap<>();

    public synchronized void set(String token, String clientUrl) {
        Set<String> clientUrlSet = tokenAndClientUrlsMap.get(token);
        if (clientUrlSet == null) {
            clientUrlSet = new HashSet<>();
        }

        clientUrlSet.add(clientUrl);
        tokenAndClientUrlsMap.put(token, clientUrlSet);
    }

    public Set<String> getClientUrl(String token) {
        return tokenAndClientUrlsMap.remove(token);
    }
}
